package com.sm42.goodsService.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.sm42.baseService.impl.BaseCrmpServiceImpl;
import com.sm42.goodsEntity.Type;
import com.sm42.goodsService.TypeService;
import com.sm42.mapper.goodsMapper.TypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Service
public class TypeServiceImpl extends BaseCrmpServiceImpl<Type> implements TypeService {
    @Autowired
    private TypeMapper typeMapper;

    @Override
    public List<Type> findTypeName(String type) {
        QueryWrapper<Type> wrapper = new QueryWrapper<>();
        wrapper.eq("class_name", type);
        List<Type> classList = typeMapper.selectList(wrapper);
        return classList;
    }

    @Override
    public int deleteType(Long id) {
        return deleteById(id);
    }

    @Override
    public Type findTypeById(Long id) {
        return findById(id);
    }

    @Override
    public int addType(Type type) {
        type.setCreateTime(LocalDateTime.now());
        return add(type);
    }

    @Override
    public int updateType(Type type) {
        type.setUpdateTime(LocalDateTime.now());
        return update(type);
    }

    @Override
    public List<Type> findSearch(Type type) {
        QueryWrapper<Type> wrapper = new QueryWrapper<>();
        wrapper.eq(type.getClassId() != 0,"class_id",type.getClassId())
                .like(ObjectUtils.isNotNull(type.getClassName()),"class_name",type.getClassName())
                .like(ObjectUtils.isNotNull(type.getClassDes()),"class_des",type.getClassDes());
        List<Type> types = typeMapper.selectList(wrapper);
        return types;
    }
}
